High Performing Players

Rationale for Variable Selection

To find the best players, it was crucial that the variables taken into account consisted of the number of games that the players started in and the total number of points that a player had for the season. The number of games that a player has started is important because it shows how other teams thought highly of the player. The field goals percentage is also important because it has the overall number of field goals including 3-pointers and 2-pointers that the players correctly executed. The amount of total rebounds is also essential to know because it can be an important factor of determining possession of the ball in future games. The number of assists is crtiical as a variable because it shows how the player is the second-to-last player to touch the ball before a point is scored. Lastly, the number of points that a player had for the season is important because it shows how many times the player was able to execute a play and the throw perfectly.

Details of the Approach

This study will determine which professional players are a high-performance athlete with a low salary. To ensure that this determination is accurate, the data will first be normalized. Then, the variables will be selected and run through the k-means algorithm. The number of clusters will be determined by the Nbclust package. Then the data will be plotted to visualize the data and then the results will be validated.

####Merging the Datasets

# converting the data into data frame format 
nba <- as.data.frame(nba)
nba_sal <-as.data.frame(nba_sal)
nba <- merge(nba, nba_sal)
# to remove multiple players: nba <- distinct_at(nba, Player)
nba <- nba[complete.cases(nba), ]
nba <- as.data.frame(nba)

# normalize the columns before they're added 
nba$GS <- normalize(nba$GS)
nba$FG <- scale(nba$FG, center= TRUE, scale = TRUE)
nba$TRB <- normalize(nba$TRB)
nba$AST <- normalize(nba$AST)
nba$PTS <- normalize(nba$PTS)

# Subsetting the data with the selected variables 
clust_data = nba[, c("Age", "G", "GS","MP", "FG","3P%","2P%","eFG%", "FT%", "TRB", "AST","STL", "BLK", "TOV", "PTS" )] #
clust_data = normalize(clust_data)
View(clust_data)
View(nba)

Finding the ideal number of clusters

# using the NbClust algorithm to find the ideal number of clusters 
(nbclust_obj_nba = NbClust(data = clust_data, method= "kmeans"))

## *** : The Hubert index is a graphical method of determining the number of clusters.
##                 In the plot of Hubert index, we seek a significant knee that corresponds to a 
##                 significant increase of the value of the measure i.e the significant peak in Hubert
##                 index second differences plot. 
## 

## *** : The D index is a graphical method of determining the number of clusters. 
##                 In the plot of D index, we seek a significant knee (the significant peak in Dindex
##                 second differences plot) that corresponds to a significant increase of the value of
##                 the measure. 
##  
## ******************************************************************* 
## * Among all indices:                                                
## * 4 proposed 2 as the best number of clusters 
## * 13 proposed 3 as the best number of clusters 
## * 1 proposed 4 as the best number of clusters 
## * 1 proposed 9 as the best number of clusters 
## * 1 proposed 14 as the best number of clusters 
## * 3 proposed 15 as the best number of clusters 
## 
##                    ***** Conclusion *****                            
##  
## * According to the majority rule, the best number of clusters is  3 
##  
##  
## *******************************************************************
## $All.index
##        KL       CH Hartigan      CCC    Scott Marriot TrCovW TraceW  Friedman
## 2  3.8170 1028.282 598.7915  25.1521 4096.224       0 4.1012 8.0486  8934.998
## 3  3.6694 1549.858 255.9445 -11.0346 4556.171       0 0.6614 3.2994  9030.297
## 4  1.4964 1751.556 264.5820 -20.7778 4841.865       0 0.2430 2.0408  9348.392
## 5  2.4717 2213.999 143.1475 -21.5722 5116.271       0 0.0842 1.2451  9374.905
## 6  1.6078 2407.889 110.7261 -26.1628 5275.322       0 0.0437 0.9246  9317.825
## 7  1.4584 2558.077  91.0065 -33.1561 5420.672       0 0.0253 0.7288  9423.771
## 8  0.8839 2684.600 128.1827 -27.8202 5546.898       0 0.0159 0.5966  9680.998
## 9  3.7590 3091.889  40.7452 -19.7448 5689.576       0 0.0081 0.4545  9812.636
## 10 0.9499 3019.267  45.4503 -17.8042 5769.981       0 0.0064 0.4134  9821.334
## 11 1.1697 3017.178  42.1336 -15.3673 5848.723       0 0.0049 0.3719  9913.053
## 12 2.1757 3023.224  22.2266 -13.0847 5913.528       0 0.0038 0.3370  9998.356
## 13 0.4059 2917.651  53.1801 -12.3230 5963.893       0 0.0033 0.3195 10089.425
## 14 1.1128 3043.418  53.1041  -9.0067 6094.934       0 0.0023 0.2825 10370.676
## 15 2.0227 3193.369  29.3662  -5.6263 6178.730       0 0.0016 0.2496 10484.558
##       Rubin Cindex     DB Silhouette   Duda Pseudot2   Beale Ratkowsky   Ball
## 2   13.7424 0.2866 0.6343     0.5821 0.4927 282.1426 10.5849    0.3475 4.0243
## 3   33.5232 0.2679 0.5850     0.5840 0.9395  14.1150  0.6614    0.3253 1.0998
## 4   54.1981 0.2874 0.6124     0.5435 0.7429  62.9932  3.5441    0.2967 0.5102
## 5   88.8353 0.2381 0.5945     0.5497 1.0938 -13.1264 -0.8775    0.2729 0.2490
## 6  119.6260 0.2678 0.6264     0.5219 1.4670 -32.1524 -3.2482    0.2520 0.1541
## 7  151.7759 0.2473 0.6553     0.4963 1.2757 -19.8815 -2.1941    0.2325 0.1041
## 8  185.3831 0.2922 0.6684     0.4913 1.0295  -2.4926 -0.2902    0.2191 0.0746
## 9  243.3414 0.2554 0.6655     0.4969 2.4989 -69.5787 -6.0508    0.2084 0.0505
## 10 267.5835 0.2450 0.7039     0.4790 0.6096  41.6194  6.4905    0.1993 0.0413
## 11 297.3917 0.2339 0.7193     0.4660 4.2484 -71.1093 -7.6713    0.1904 0.0338
## 12 328.1784 0.2233 0.7357     0.4450 2.5733 -39.1293 -6.1287    0.1824 0.0281
## 13 346.1447 0.2204 0.7492     0.4363 0.7197  18.3067  3.9196    0.1761 0.0246
## 14 391.5965 0.2309 0.7848     0.4306 2.7733 -30.0524 -6.3167    0.1711 0.0202
## 15 443.0702 0.2153 0.7940     0.4210 2.4788 -29.8292 -5.8936    0.1650 0.0166
##    Ptbiserial   Frey McClain   Dunn Hubert SDindex Dindex   SDbw
## 2      0.6554 0.6636  0.3727 0.0210 0.0357 28.7353 0.1210 1.5371
## 3      0.6628 1.1713  0.5186 0.0264 0.0456 17.6744 0.0774 0.5443
## 4      0.6048 0.8210  0.6503 0.0386 0.0499 17.8616 0.0622 0.5236
## 5      0.5627 1.1208  0.7190 0.0314 0.0533 18.8373 0.0480 0.2718
## 6      0.5251 1.2721  0.7925 0.0406 0.0547 22.0371 0.0421 0.3480
## 7      0.4879 0.8201  0.8801 0.0370 0.0554 27.6344 0.0375 0.3473
## 8      0.4714 0.8812  0.9031 0.0365 0.0562 28.9251 0.0339 0.1567
## 9      0.4437 1.5847  0.9468 0.0552 0.0566 33.9304 0.0296 0.0582
## 10     0.4274 1.7697  0.9995 0.0552 0.0567 49.2226 0.0281 0.0299
## 11     0.4064 1.5159  1.0798 0.0365 0.0568 56.8172 0.0265 0.0310
## 12     0.3885 2.7851  1.1518 0.0578 0.0569 62.7915 0.0252 0.0268
## 13     0.3785 0.6694  1.2061 0.0584 0.0570 79.5621 0.0243 0.0236
## 14     0.3685 1.0415  1.2201 0.0651 0.0572 77.2647 0.0230 0.0214
## 15     0.3503 1.4111  1.2891 0.0514 0.0575 85.5277 0.0216 0.0155
## 
## $All.CriticalValues
##    CritValue_Duda CritValue_PseudoT2 Fvalue_Beale
## 2          0.8799            37.4091       0.0000
## 3          0.8666            33.7209       0.8243
## 4          0.8529            31.3800       0.0000
## 5          0.8461            27.8256       1.0000
## 6          0.8336            20.1670       1.0000
## 7          0.8108            21.4624       1.0000
## 8          0.8015            21.5528       1.0000
## 9          0.7862            31.5395       1.0000
## 10         0.8043            15.8138       0.0000
## 11         0.7681            28.0705       1.0000
## 12         0.7655            19.6097       1.0000
## 13         0.7779            13.4216       0.0000
## 14         0.7256            17.7759       1.0000
## 15         0.7256            18.9105       1.0000
## 
## $Best.nc
##                    KL       CH Hartigan     CCC    Scott Marriot TrCovW TraceW
## Number_clusters 2.000   15.000    3.000  2.0000   3.0000       3 3.0000 3.0000
## Value_Index     3.817 3193.369  342.847 25.1521 459.9466       0 3.4398 3.4906
##                 Friedman    Rubin  Cindex    DB Silhouette   Duda PseudoT2
## Number_clusters    4.000   9.0000 15.0000 3.000      3.000 3.0000    3.000
## Value_Index      318.096 -33.7163  0.2153 0.585      0.584 0.9395   14.115
##                  Beale Ratkowsky   Ball PtBiserial Frey McClain    Dunn Hubert
## Number_clusters 3.0000    2.0000 3.0000     3.0000    1  2.0000 14.0000      0
## Value_Index     0.6614    0.3475 2.9245     0.6628   NA  0.3727  0.0651      0
##                 SDindex Dindex    SDbw
## Number_clusters  3.0000      0 15.0000
## Value_Index     17.6744      0  0.0155
## 
## $Best.partition
##   1   2   3   4   5   6   7   9  10  11  12  13  14  15  16  18  19  20  21  22 
##   1   1   2   2   2   1   1   1   2   2   2   2   2   2   2   1   1   2   3   1 
##  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42 
##   1   3   2   1   1   2   3   2   3   1   1   1   2   1   3   1   2   3   3   1 
##  43  44  45  46  47  48  49  50  51  52  53  54  55  57  58  59  60  61  62  63 
##   2   2   1   3   2   1   1   2   2   3   2   3   2   3   3   2   1   1   2   1 
##  65  66  67  68  69  70  72  73  74  75  76  77  79  80  81  83  84  85  86  87 
##   3   2   1   1   3   1   1   1   2   1   2   2   3   1   1   2   1   1   3   2 
##  88  89  90  91  92  93  94  95  96  97  98  99 100 101 103 104 105 106 107 108 
##   1   2   2   3   3   2   1   3   1   2   2   1   3   1   3   3   3   1   1   3 
## 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 
##   2   2   2   1   1   3   2   1   2   2   1   3   1   1   3   3   3   3   1   3 
## 129 131 132 133 134 135 136 138 139 140 141 143 144 145 146 147 149 150 151 152 
##   3   3   3   1   2   1   2   2   3   3   2   3   1   1   1   1   1   2   3   1 
## 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 173 174 
##   3   1   1   3   2   1   3   2   2   1   3   2   1   1   1   3   2   2   1   2 
## 175 177 178 179 180 181 182 183 185 186 187 188 190 191 193 194 195 196 197 198 
##   3   2   1   1   2   1   1   1   1   3   3   2   2   2   1   2   2   2   3   1 
## 199 200 201 202 203 204 206 208 209 210 211 212 214 215 216 217 218 219 220 221 
##   3   3   2   1   1   1   1   1   3   2   2   2   3   2   3   3   1   3   1   2 
## 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 
##   2   1   3   3   3   3   2   1   1   3   2   2   2   3   1   1   1   1   2   3 
## 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 
##   3   2   2   2   1   3   2   3   3   3   1   3   1   1   3   2   1   3   2   2 
## 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 
##   2   1   3   2   2   1   1   3   3   3   2   1   3   1   2   1   1   3   1   3 
## 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 
##   1   3   2   3   1   2   2   3   3   1   1   1   1   2   1   2   3   3   1   2 
## 302 303 305 306 307 308 309 310 311 312 314 315 316 317 318 319 320 321 322 323 
##   2   1   2   1   1   3   3   1   2   3   2   2   3   3   2   2   3   2   1   2 
## 324 326 327 328 329 330 331 332 334 338 339 340 341 342 343 344 345 346 348 349 
##   1   1   2   3   3   2   3   3   3   2   1   2   2   3   3   3   1   1   2   2 
## 350 351 352 353 355 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 
##   3   1   3   1   1   2   2   2   2   1   3   1   3   3   3   3   1   2   1   2 
## 372 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 
##   2   1   2   3   1   3   1   3   2   1   2   1   1   3   3   3   1   2   2   1 
## 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 410 411 412 413 
##   2   1   3   1   3   1   1   2   2   2   1   2   2   1   1   1   3   3   1   1 
## 414 415 416 417 418 419 420 421 423 424 425 426 427 428 429 431 432 433 434 435 
##   2   2   2   3   1   3   1   2   2   3   2   1   2   1   2   1   2   2   3   1 
## 436 438 439 440 441 443 444 445 446 448 449 450 451 452 453 454 455 456 
##   1   2   1   1   2   2   1   1   1   2   1   3   1   2   1   3   2   3
# subset the first row from Best.nc and convert to a data frame 
freq_k_nba = nbclust_obj_nba$Best.nc[1,]
freq_k_nba = data.frame(freq_k_nba)

#Plot the recommended number of clusters as a histogram 
ggplot(freq_k_nba, aes(x = freq_k_nba)) + geom_bar()+ scale_x_continuous(breaks = seq(0, 15, by = 1)) + scale_y_continuous(breaks = seq(0, 12, by = 1)) + labs(x = "Number of Clusters", y = "Number of Votes", title = "Cluster Analysis")

From the cluster analysis, the recommended number of clusters is 3.

Run the K-means algorithm

# Run an algorithm with  centers and make the results reproducible with set.seed 
set.seed(1)
kmeans_obj_nba = kmeans(clust_data, centers = 3, algorithm = "Lloyd")
head(kmeans_obj_nba)
## $cluster
##   1   2   3   4   5   6   7   9  10  11  12  13  14  15  16  18  19  20  21  22 
##   1   1   2   2   2   1   1   1   2   2   2   2   2   2   2   1   1   2   3   1 
##  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42 
##   1   3   2   1   1   2   3   2   3   1   1   1   2   1   3   1   2   3   3   1 
##  43  44  45  46  47  48  49  50  51  52  53  54  55  57  58  59  60  61  62  63 
##   2   2   1   3   2   1   1   2   2   3   2   3   2   3   3   2   1   1   2   1 
##  65  66  67  68  69  70  72  73  74  75  76  77  79  80  81  83  84  85  86  87 
##   3   2   2   1   3   1   1   1   2   1   2   2   3   1   1   2   1   1   3   2 
##  88  89  90  91  92  93  94  95  96  97  98  99 100 101 103 104 105 106 107 108 
##   1   2   2   3   3   2   1   3   1   2   2   1   3   1   3   3   3   1   1   3 
## 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 
##   2   2   2   1   1   1   2   1   2   2   1   3   1   1   3   3   3   3   1   3 
## 129 131 132 133 134 135 136 138 139 140 141 143 144 145 146 147 149 150 151 152 
##   3   3   3   1   2   2   2   2   3   3   2   3   1   1   1   1   1   2   3   1 
## 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 173 174 
##   3   1   1   3   2   1   3   2   2   1   3   2   1   1   1   3   2   2   1   2 
## 175 177 178 179 180 181 182 183 185 186 187 188 190 191 193 194 195 196 197 198 
##   3   2   1   1   2   1   1   1   1   3   3   2   2   2   1   2   2   2   3   1 
## 199 200 201 202 203 204 206 208 209 210 211 212 214 215 216 217 218 219 220 221 
##   3   3   2   1   1   1   1   1   3   2   2   2   3   2   3   3   1   3   1   2 
## 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 
##   2   1   3   3   3   3   2   1   1   3   2   2   2   3   1   1   1   1   2   3 
## 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 
##   3   2   2   2   1   3   2   3   3   3   1   1   1   1   3   2   1   3   2   2 
## 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 
##   2   1   3   2   2   1   1   3   3   3   2   1   3   1   2   1   1   3   1   3 
## 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 
##   1   3   2   3   1   2   2   3   3   1   1   1   1   2   1   2   3   3   1   2 
## 302 303 305 306 307 308 309 310 311 312 314 315 316 317 318 319 320 321 322 323 
##   2   1   2   1   1   3   3   1   2   3   2   2   3   3   2   2   3   2   1   2 
## 324 326 327 328 329 330 331 332 334 338 339 340 341 342 343 344 345 346 348 349 
##   1   1   2   3   3   2   3   3   3   2   1   2   2   3   3   3   1   1   2   2 
## 350 351 352 353 355 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 
##   3   1   3   1   1   2   2   2   2   1   1   1   3   3   3   3   1   2   1   2 
## 372 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 
##   2   1   2   3   1   3   1   3   2   1   2   1   1   3   1   3   1   2   2   1 
## 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 410 411 412 413 
##   2   1   3   1   3   1   1   2   2   2   1   2   2   1   1   1   3   3   1   1 
## 414 415 416 417 418 419 420 421 423 424 425 426 427 428 429 431 432 433 434 435 
##   2   2   2   3   1   3   1   2   2   3   2   1   2   1   2   1   2   2   3   1 
## 436 438 439 440 441 443 444 445 446 448 449 450 451 452 453 454 455 456 
##   1   2   1   1   2   2   1   1   1   2   1   3   1   2   1   3   2   3 
## 
## $centers
##          Age          G           GS        MP           FG         3P%
## 1 0.02054189 0.02174322 0.0011414986 0.4705292 0.0008859540 0.001169983
## 2 0.01942502 0.01240011 0.0009604542 0.1514115 0.0002508212 0.001138877
## 3 0.02041617 0.02546459 0.0014791082 0.7663710 0.0017975619 0.001182005
##           2P%        eFG%         FT%          TRB          AST         STL
## 1 0.001297632 0.001314167 0.001486702 0.0010937955 0.0010438441 0.016220821
## 2 0.001293589 0.001293742 0.001436110 0.0009769641 0.0009562825 0.005666418
## 3 0.001310994 0.001323228 0.001507254 0.0012125384 0.0011898356 0.024367383
##           BLK         TOV         PTS
## 1 0.010484227 0.024616176 0.001107860
## 2 0.004521996 0.008578561 0.000972334
## 3 0.014936477 0.049013315 0.001304945
## 
## $totss
## [1] 27.9435
## 
## $withinss
## [1] 1.133004 1.117633 1.051747
## 
## $tot.withinss
## [1] 3.302384
## 
## $betweenss
## [1] 24.64111
clusters = as.factor(kmeans_obj_nba$cluster)
clusters = as.data.frame(clusters)

Visualizing Various Plots and Correlations

####Correlation between the Salary and Points

# This plot shows the correlation between the games started and the points each player has 
sal_clusters = as.factor(kmeans_obj_nba$cluster)
b <-ggplot(nba, aes(x = Salary, y = PTS, color = sal_clusters, text=Player))+geom_point(size = 6)+ggtitle("Salary vs. Points for NBA Basketball players") +xlab("Salary")+ylab("Number of Points")+scale_shape_manual(name = "Cluster", labels = c("Cluster 1", "Cluster 2", "Cluster 3"), values = c("1", "2", "3"))+ theme_light()
ggplotly(b, tooltip="text")

####Correlation between Salary and Games Started

sal_clusters = as.factor(kmeans_obj_nba$cluster)
c <-ggplot(nba, aes(x = Salary, y = GS, color = sal_clusters, text=Player))+geom_point(size = 6) + ggtitle("Salary vs. Games started by NBA Basketball players") + xlab("Salary")+ylab("Number of Games Started") + scale_shape_manual(name = "Cluster", labels = c("Cluster 1", "Cluster 2", "Cluster 3"), values = c("1", "2","3"))+ theme_light()
ggplotly(c, tooltip="text")

####Correlation between the Salary and Field Goals

sal_clusters = as.factor(kmeans_obj_nba$cluster)
a <-ggplot(nba, aes(x = Salary, y = FG, color = sal_clusters, text = Player))+geom_point(size = 6) + ggtitle("Salary vs. Field Goals for NBA Basketball players") + xlab("Salary")+ylab("Number of Field Goals") + scale_shape_manual(name = "Cluster", labels = c("Cluster 1", "Cluster 2", "Cluster 3"), values = c("1", "2", "3"))+ theme_light()
ggplotly(a, tooltip="text")

####Correlation between the Salary and Number of Assists

sal_clusters = as.factor(kmeans_obj_nba$cluster)
a <-ggplot(nba, aes(x = Salary, y = AST, color = sal_clusters, text = Player))+geom_point(size = 6) + ggtitle("Salary vs. Assists for NBA Basketball players") + xlab("Salary")+ylab("Number of Assists") + scale_shape_manual(name = "Cluster", labels = c("Cluster 1", "Cluster 2", "Cluster 3"), values = c("1", "2", "3"))+ theme_light()
ggplotly(a, tooltip="text")

Final Recommendations

I would recommend Trae Young, Luka Don, Donovan Mitchell, and Zion Williamson I recommend these three players because they have done well in terms of how many field goals they’ve completed during the last season as well as the number of points that they accumulated. They are also not paid as well as the other athletes and seem to be high-performing. These players seem to have a high number of points compared to others and are on the lower end of the salary spectrum.